package org.smartboot.flow.core.parser.definition;

import org.smartboot.flow.core.component.IfComponent;
import org.smartboot.flow.core.parser.DefinitionVisitor;
import org.smartboot.flow.core.util.AssertUtil;

/**
 * @author huqiang
 * @since 2022/11/16 15:30
 */
public class IfElementDefinition extends ElementDefinition {

    private ElementDefinition ifThenRef;

    private ElementDefinition ifElseRef;

    public ElementDefinition getIfThenRef() {
        return this.ifThenRef;
    }

    public void setIfThenRef(ElementDefinition ifThenRef) {
        this.ifThenRef = ifThenRef;
    }

    public ElementDefinition getIfElseRef() {
        return this.ifElseRef;
    }

    public void setIfElseRef(ElementDefinition ifElseRef) {
        this.ifElseRef = ifElseRef;
    }

    @Override
    public void validate() {
        super.validate();
        AssertUtil.notNull(ifThenRef, "if element named " + name + " lack then tag");

        ifThenRef.validate();
        if (ifElseRef != null) {
            ifElseRef.validate();
        }
    }

    @Override
    public void visit0(DefinitionVisitor visitor) {
        visitor.visit(this);
    }

    @Override
    public Class<?> resolveType() {
        return IfComponent.class;
    }
}
